package com.tan.utils;

import com.tan.dom4jdome.Dom4jImpl;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

/**
 * @Author 谭永超 [www.tanyongchao.tk:8090/SumDome/index]
 * @Date 2018/8/21 20:43
 * @Description 时间转换工具类
 */
public class DateUtils {
    /**
     * @Author 谭永超 [www.tanyongchao.tk:8090/SumDome/index]
     * @Date 2018/8/16 11:25
     * @Description 日期
     */
    public static Date formatDate(String date) {
        DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        try {
            return format.parse(date);
        } catch (Exception e) {
            LogUtils.LogInfo(Dom4jImpl.class, "时间格式转换异常");
            return null;
        }
    }

    /**
     * @Author 谭永超 [www.tanyongchao.tk:8090/SumDome/index]
     * @Date 2018/8/16 11:25
     * @Description 时间
     */
    public static Date formatTime(String date) {
        DateFormat format = new SimpleDateFormat("HH:mm");
        try {
            return format.parse(date);
        } catch (Exception e) {
            LogUtils.LogInfo(Dom4jImpl.class, "时间格式转换异常");
            return null;
        }
    }
    /**
     * @Author 谭永超 [www.tanyongchao.tk:8090/SumDome/index]
     * @Date 2018/8/6 14:24
     * @Description 将时间清除为零
     */
    public static Date currentDate(Date date) {
        // 当前时间
        Calendar calendar = new GregorianCalendar();
        Date date1 = new Date();
        Calendar calendar1 = new GregorianCalendar();
        calendar.setTime(date);
        calendar1.setTime(date1);
        // 小时为零
        calendar.set(Calendar.HOUR,00);
        // 分钟为零
        calendar.set(Calendar.MINUTE,00);
        // 秒为零
        calendar.set(Calendar.SECOND,00);
        date = calendar.getTime();
        System.out.println("时间" + date);
        return date;
    }
}
